﻿using System;
using System.Collections.Generic;
using System.Text;

namespace daSyntaxAnalyser.SyntaxTree
{
    using daBase.Objects;

    public class InterfacePropertyElement : IdElement, ISectionElementElement
    {
        protected IndexIntervalElement indexinterval;
        protected ITypeElement type;
        protected ConstExpressionElement index;
        protected PropertyOptionElement read, write, stored, _default;

        public IndexIntervalElement IndexInterval { get { return indexinterval; } set { indexinterval = value; } }
        public ITypeElement Type { get { return type; } set { type = value; } }
        public ConstExpressionElement Index { get { return index; } set { index = value; } }
        public PropertyOptionElement Read { get { return read; } set { read = value; } }
        public PropertyOptionElement Write { get { return write; } set { write = value; } }
        public PropertyOptionElement Stored { get { return stored; } set { stored = value; } }
        public PropertyOptionElement Default { get { return _default; } set { _default = value; } }

        public InterfacePropertyElement(TokenInfo Id, IndexIntervalElement IndexInterval, ITypeElement Type, ConstExpressionElement Index, PropertyOptionElement Read, PropertyOptionElement Write, PropertyOptionElement Stored, PropertyOptionElement Default, List<TokenInfo> Comments)
            : base(Id, Comments)
        {
            indexinterval = IndexInterval;
            type = Type;
            index = Index;
            read = Read;
            write = Write;
            stored = Stored;
            _default = Default;
        }

        public override string ToString()
        {
            string result = string.Format("property {0}", id);
            if (indexinterval != null) result += string.Format(" {0}", indexinterval);
            if (type != null) result += string.Format(" : {0}", type);
            if (index != null) result += string.Format("index {0}", index);
            if (read != null) result += string.Format(" {0}", read);
            if (write != null) result += string.Format(" {0}", write);
            if (stored != null) result += string.Format(" {0}", stored);
            if (_default != null) result += string.Format(" {0}", _default);
            return string.Format("{0};", result);
        }

        protected override IEnumerator<ISyntaxTreeElement> CreateEnumerator()
        {
            if (indexinterval!=null) yield return indexinterval;
            if (type != null) yield return type;
            if (index != null) yield return index;
            if (read != null) yield return read;
            if (write != null) yield return write;
            if (stored != null) yield return stored;
            if (_default != null) yield return _default;
        }
    }
}
